//============================================================================
// Name        : NautilusLabC.cpp
// Author      : Dao Anh Vu
// Version     : 
// Copyright   : Your copyright notice
// Description : NautilusLab in C++, Microsoft Visual C++ 
//============================================================================

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static TCHAR szWindowClass[] = _T("NautilusLab");
static TCHAR szAppTitle[] = _T("Nautilus Lab 1.0");

HINSTANCE ghInstance;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nCmdShow) {
	WNDCLASSEX wndclsex;
	MSG msg;
	HWND hwnd;
	
	wndclsex.cbSize = sizeof(WNDCLASSEX);
	wndclsex.style = CS_HREDRAW | CS_VREDRAW;
	wndclsex.lpfnWndProc = WndProc;
	wndclsex.cbClsExtra = 0;
	wndclsex.cbWndExtra = 0;
	wndclsex.hInstance = hInstance;
	wndclsex.hIcon = LoadIcon(hInstance, MAKEINRESOURCE(IDI_APPLICATION));
	wndclsex.hCursor = LoadCursor(NULL, IDC_ARROW);	
	wndclsex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wndclsex.lpszMenuName = NULL;
	wndclsex.lpszClsName = szWindowClass;
	wndclsex.hIconSm = LoadIcon(hInstance, MAKEINRESOURCE(IDI_APPLICATION));
	
	if(!RegisterClassEx(&wndclsex)){
		MessageBox(NULL, _T("Cannot register window class"), szAppTitle, NULL);
		return 1;
	}
	
	ghInstance = hInstance;
	hwnd = CreateWindow(szWindowClass, szAppTitle, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 100,
        NULL,
        NULL,
        hInstance,
        NULL);
		
	if(!hwnd){
		MessageBox(NULL, _T("Cannot create window"), szAppTitle, NULL);
		return 1;
	}
	
	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);
	
	while(GetMessage(&msg, NULL, 0, 0)){
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	
	return (int)msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {

	switch(msg){
		case WM_PAINT:
		break;
		
		case WM_DESTROY:
			PostQuitMessage(0);
		break;
		
		default:
			return DefWindowProc(hwnd, msg, wparam, lparam);
	}
	
	return 0;
}